import requests
from lxml import etree
import re
#https://search.jd.com/Search?keyword=%E8%B7%AF%E7%94%B1%E5%99%A8&enc=utf-8&spm=a.0.0&pvid=7b092906b19146eab7bc825dd3b8e1c9?start=
#https://search.jd.com/Search?keyword=%E6%89%8B%E6%9C%BA&enc=utf-8&qrst=1&rt=1&stop=1&vt=2&cid2=653&cid3=655&page='+str(2*n-1)
for i in range(0,2):
    url='https://search.jd.com/Search?keyword=%E8%B7%AF%E7%94%B1%E5%99%A8&spm=a.0.0&page=1&s=90&click=0'
    headers = {
                'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36',
                'cookie': '__jdv=76161171|direct|-|none|-|1588471423578; __jdu=1588471423576964192718; shshshfpa=14f6118d-e285-8dd9-9640-558b573ade57-1588471427; shshshfpb=vv%2FiVsq9yI8aKJNXYX%2Ft3oA%3D%3D; xtest=156.cf6b6759; 3AB9D23F7A4B3C9B=GARCMGOIU4I3I7BCWJFGPI3Y7GYJKJKHRDKB7UY6EVCSNEABISDMRXEU2JDFLNPHQDHODDVAWN47GXY2M3H7A7WDCE; qrsc=3; shshshfp=15f6e32a565dfb41091b6e0440e9ef17; areaId=18; ipLoc-djd=18-1482-0-0; __jdc=122270672; rkv=V0800; Hm_lvt_eaa57ca47dacb4ad4f5a257001a3457c=1588472489,1588478634,1589448948,1589508053; Hm_lpvt_eaa57ca47dacb4ad4f5a257001a3457c=1589508053; __jda=122270672.1588471423576964192718.1588471424.1589508046.1589519653.6; __jdb=122270672.1.1588471423576964192718|6.1589519653; shshshsID=b10ed6528b16a3cd9134e9b45f63bef5_1_1589519654346'

    }
    response=requests.get(url,headers=headers)
    response.encoding=response.apparent_encoding
    data=response.text

    html=etree.HTML(data)
    total_data=html.xpath('//ul[@class="gl-warp clearfix"]/li')
    hrefs_list=[]
    for datas in total_data:
        hrefs=datas.xpath('.//div[@class="p-img"]/a/@href')

        # hrefs_list.append(hrefs)
        for i in hrefs:
            url='https:'+i
            hrefs_list.append(url)
# print(len(hrefs_list))
for i in hrefs_list:
    response=requests.get(i,headers=headers)
    response.encoding=response.apparent_encoding
    data=response.text
    html=etree.HTML(data)
    # print(i)


















#https://search.jd.com/Search?keyword=%E8%B7%AF%E7%94%B1%E5%99%A8&spm=a.0.0&page=3&s=90&click=0
#https://search.jd.com/Search?keyword=%E8%B7%AF%E7%94%B1%E5%99%A8&spm=a.0.0&page=7&s=150&click=06